<?php

namespace App\Http\Controllers\API;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Novel;
use App\Model\NovelChapter;
use Illuminate\Support\Facades\DB;

class NovelsController extends Controller
{
    public function lists ()
    {
        $result = Novel::all();
        return response()->json($result);
    }

    public function detail ($id)
    {
        $result = Novel::find($id);
        $result['chapters'] = Novel::find($id)->chapter;
        //return response()->json(Novel::find($id));
        return response()->json($result);
    }

    public function chapter ($id) {
        $result = NovelChapter::find($id);
        $result['novel']= NovelChapter::find($id)->novel;
        return response()->json($result);
    }

    public function test ($id)
    {
        return response()->json(Novel::find()->chapter);
    }
}
